import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo:{},
    menuList:[]
  },
  getters: {
    rolemenus(state){
      return state.userInfo?.role?.menus
    }
  },
  mutations: {
    updateMenus(state,payload){
      state.menuList = payload;
    },
    updateUserInfo(state,payload){
      state.userInfo = {...state.userInfo, ...payload};
    }
  },
  actions: {
  },
  modules: {
  },
  plugins:[
    createPersistedState({
        // 存储方式：localStorage、sessionStorage、cookies
        storage: window.localStorage,
        // 存储的 key 的key值
        key: "userstore",
        render(state) {
        // 要存储的数据：本项目采用es6扩展运算符的方式存储了state中所有的数据
            return { ...state };
        }
    })
]
})
